package com.jinghui.xiaoyuanliao.ui;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.jinghui.xiaoyuanliao.ui.linkman.LinkmanFragment;
import com.jinghui.xiaoyuanliao.ui.news.NewsFragment;
import com.jinghui.xiaoyuanliao.ui.other.OtherFragment;

/**
 * Created by pc on 2016/11/2.
 */

public class FragmentFactory {
    private static final int FRAGMENT_NEWS = 0;
    private static final int FRAGMENT_LINKMAN = 1;
    private static final int FRAGMENT_OTHER = 2;
    private static SparseArray<Fragment> list = new SparseArray<>();

    public static Fragment setFragment(int key){
        Fragment fragment = list.get(key);
        if (fragment == null){
            switch (key){
                case FRAGMENT_NEWS:
                    fragment =  NewsFragment.setFragment();
                    break;
                case FRAGMENT_LINKMAN:
                    fragment = LinkmanFragment.setLinkmanFragment();
                    break;
                case FRAGMENT_OTHER:
                    fragment = OtherFragment.setOtherFragment();
                    break;
            }
        }
        return fragment;
    }
}
